package com.itheima.edu.info.manger.dao;

import com.itheima.edu.info.manger.contrller.BaseStudentContrller;
import com.itheima.edu.info.manger.domain.Student;

import java.util.ArrayList;

public class OotherStudentDao extends BaseStudentDao {
    private static ArrayList<Student>  stus= new ArrayList<>();
    static {
        Student stu1=new Student("22","张三","44","44444");
     Student stu2=new Student("255","张","48","44444");
     stus.add(stu1);
        stus.add(stu2);
    }
    public boolean addtudent(Student stu) {
        stus.add(stu);
        return true;
    }

    public Student[] findstudentid() {
        Student[] students=new Student[stus.size()];
        for (int i = 0; i < students.length; i++) {
            students[i]=stus.get(i);
        }
        return students;
    }

    public void deleteid(String deid) {
        //查找ID所在索引位置
      int index=gitid(deid);
        //将索引位置用NULL覆盖
        stus.remove(index);
    }
    public  int gitid(String id){ int index=-1;
                for (int i = 0; i < stus.size(); i++) {
                    Student stu=stus.get(i);
                    if(stu !=null && stu.getId().equals(id)){
                        index=i;
                        break;
                    }
        }
return index;
    }

    public void updatastudent(String upid, Student sutnew) {
        //查找updatastudent的索引位置
        int index= gitid(upid);
        //将索引位置使用新的信息替换
    stus.set(index,sutnew);
    }
}

